#pragma once

#include "ReadLinkObjectEndAction.h"

#include "InputPin.h"
#include "OutputPin.h"
#include "Property.h"

namespace uml {

ReadLinkObjectEndAction::ReadLinkObjectEndAction(const QString& umlType)
    : Action(umlType) {}

void ReadLinkObjectEndAction::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    Action::fromJson(json, errorList);
    end_ = JsonSerializable::create<Property>(json.value("end"), errorList);

    object_ = JsonSerializable::create<InputPin>(json.value("object"), errorList);

    result_ = JsonSerializable::create<OutputPin>(json.value("result"), errorList);

}

void ReadLinkObjectEndAction::toJson(QJsonObject& json) {
    Action::toJson(json);
    if (end_) {
        QJsonObject end_json;
        end_->toJson(end_json);
        json.insert("end", end_json);
    }
    if (object_) {
        QJsonObject object_json;
        object_->toJson(object_json);
        json.insert("object", object_json);
    }
    if (result_) {
        QJsonObject result_json;
        result_->toJson(result_json);
        json.insert("result", result_json);
    }
}

/// <summary>
/// end getter
/// The Association end to be read.
/// </summary>
shared_ptr<Property> ReadLinkObjectEndAction::end() const {
    return end_;
}

/// <summary>
/// end setter
/// The Association end to be read.
/// </summary>
void ReadLinkObjectEndAction::setEnd(shared_ptr<Property> value) {
    end_ = value;
}

/// <summary>
/// object getter
/// The input pin from which the link object is obtained.
/// </summary>
shared_ptr<InputPin> ReadLinkObjectEndAction::object() const {
    return object_;
}

/// <summary>
/// object setter
/// The input pin from which the link object is obtained.
/// </summary>
void ReadLinkObjectEndAction::setObject(shared_ptr<InputPin> value) {
    object_ = value;
}

/// <summary>
/// result getter
/// The OutputPin where the result value is placed.
/// </summary>
shared_ptr<OutputPin> ReadLinkObjectEndAction::result() const {
    return result_;
}

/// <summary>
/// result setter
/// The OutputPin where the result value is placed.
/// </summary>
void ReadLinkObjectEndAction::setResult(shared_ptr<OutputPin> value) {
    result_ = value;
}

} // namespace uml
